package com.file.controller;

import com.file.form.result.ImgResultForm;
import com.file.service.IFileProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by chairal on 2017/7/21.
 * 文件的上传，下载
 */
@RestController
@RequestMapping("/file")
public class FileProcessController {

    @Autowired
    IFileProcessService fileProcessService;

    /**
     * 文件上传
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/upload")
    @ResponseBody
    public ImgResultForm uploadFile(HttpServletRequest request, HttpServletResponse response) {
        return fileProcessService.uploadFile(request);
    }

    /**
     * 文件下载
     *
     * @param request
     * @param response
     */
    @RequestMapping("/down")
    @ResponseBody
    public void downFile(HttpServletRequest request, HttpServletResponse response) {
        fileProcessService.downFile(request, response);
    }

    /**
     * 上传图片到ftp服务器
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/upload/ftp")
    @ResponseBody
    public ImgResultForm uploadFtpFile(HttpServletRequest request, HttpServletResponse response) {
        return fileProcessService.uploadFtpFile(request);
    }

}
